const app = getApp()
import utils_index from '../../utils/index.js'
import {
  userModel
} from '../../apis/index.js'
import regeneratorRuntime from '../../libs/wxPromise.min'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    listIndex: 0,
    priceList:[],
    vipInfoList:[
      { title: '昵称加V彰显尊贵', img: 'wode_tequan_vip', description: '个人主页、送礼等加金色V标识，召唤群友与众不同' },
      { title: '幸运星天天领', img: 'wode_tequan_xing', description: '会员每天可领取10个幸运星' },
      { title: '集结打榜更给力', img: 'wode_tequan_jijie', description: '每曰集结次数提升至20次，每次集结热度提升为15点!' },
      { title: '会员礼物', img: 'wode_tequan_liwu', description: '可送出会员专属礼物：许愿瓶，为爰豆增加大量热度' },
      { title: '每日补签', img: 'wode_tequan_buqian', description:'再也不用担心当日漏签啦，会员可以补签哦!'},
    ],
    isIOS:true
  },
  mixins: [require('../../myMixin.js')],
  getListIndex(e) {
    let data = utils_index.getDataSet(e)
    this.setData({
      listIndex: data.index
    })
  },
  async onLoad(options) {

    let userInfo =await this.getUserInfo()

    let priceList = await userModel.vipPriceList()
    this.setData({
      userInfo:userInfo,
      priceList:priceList,
      isIOS: app.globalData.isIOS
    })
  },
  onReady: function () {

  },
  onShow: function () {

  },
  async payVIP(){
    utils_index.showLoading()
    let {listIndex,priceList} = this.data
    let item = priceList[listIndex]
    console.log(item)
    let param ={
      money:item.money,
      vip_time:item.num
    }

    let orderInfo =await userModel.prePayVip(param)
    utils_index.hideAll()
    let state = await utils_index.pay(orderInfo)
    if(state){
     let show = utils_index.showModalContent("恭喜你,购买会员成功。", `会员时长延长${item.num}天`, '确定', false)
     if(show){
      let userInfo =await this.getUserInfo()
      this.setData({
        userInfo:userInfo

      })
     }
    }  
  }
})